package com.dx.financehy.modules.system.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.annotation.*;
import com.dx.financehy.base.CommonEntity;
import com.dx.financehy.modules.system.domain.dto.DictSmallDto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
* @author jinjin
* @date 2020-09-24
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sys_dict_detail")
public class DictDetail extends CommonEntity<DictDetail> implements Serializable {

    @ApiModelProperty(value = "ID")
    @TableId(value = "detail_id", type= IdType.ASSIGN_ID)
    private String id;

    @ApiModelProperty(value = "业务参数类型ID")
    @NotNull
    private String dictId;

    @ApiModelProperty(value = "字典id")
    @NotNull
    @TableField(exist = false)
    private DictSmallDto dict;

    @ApiModelProperty(value = "字典标签")
    @NotBlank
    private String label;

    @ApiModelProperty(value = "字典值")
    //@NotBlank
    private String value;

    @ApiModelProperty(value = "排序")
    @NotNull(message = "[排序字段]不能为空")
    private Integer dictSort;

    /**
     * 删除标志：0-正常，1-删除
     */
    @JsonIgnore
    @TableLogic
    @TableField(fill= FieldFill.INSERT)
    private Boolean deleted;

    public void copyFrom(DictDetail source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
